<!--
 * @Author: Shususumu
 * @Date: 2020-10-15 15:57:45
 * @LastEditTime: 2020-10-20 19:14:06
 * @FilePath: \campusPTjobs\src\views\check\waitercheck.vue
-->
<template>
  <div id="waiter">
    <!-- 表格 -->
    <template>
      <el-table :data="waiterList" stripe style="width: 100%">
        <el-table-column fixed prop="id" label="编号" width="80">
        </el-table-column>
        <el-table-column fixed prop="realname" label="姓名" width="150">
        </el-table-column>
        <el-table-column prop="telephone" label="手机号" width="120">
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号"> </el-table-column>
        <el-table-column prop="bankCard" label="银行卡号"> </el-table-column>
        <el-table-column prop="registerTime" label="注册时间">
        </el-table-column>
        <el-table-column prop="status" label="状态" width="160">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              @click="(dialogFormVisible = true), udt(scope.row)"
              type="text"
              size="small"
              >审核</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
    <!-- 分页 -->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[6, 8, 10, 12]"
      :page-size="6"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <!-- 模态框 -->
    <el-dialog :title="title" :visible.sync="dialogFormVisible">
      <el-form :model="form" ref="waiterform">
        <el-form-item label="姓名" :label-width="formLabelWidth" prop="realname"
          >{{ realname }}
        </el-form-item>
        <el-form-item
          label="身份证号"
          :label-width="formLabelWidth"
          prop="idCard"
          >{{ idCard }}
        </el-form-item>
        <div class="demo-image__placeholder">
          <div class="block">
            <span class="demonstration"></span>
            <el-image :src="form.img1"> </el-image>
          </div>
          <br />
          <div class="block">
            <span class="demonstration"></span>
            <el-image :src="form.img2"></el-image>
          </div>
        </div>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="warning"
          @click="(dialogFormVisible = false), reauditing('waiterform')"
          >不通过</el-button
        >
        <el-button
          type="success"
          @click="(dialogFormVisible = false), auditing('waiterform')"
          >通过</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import qs from "querystring";
export default {
  data() {
    return {
      waiters: [],
      input: "",
      dialogFormVisible: false,
      title: "审核员工信息",
      realname: "",
      idCard: "",
      form: {
        id: "",
        img1: "",
        img2: "",
      },
      formLabelWidth: "100px",
      fileList: [],
      currentPage: 1,
      total: 1,
      pageSize: 6,
    };
  },
  computed: {
    waiterList() {
      this.waiters.forEach((item) => {
        item.registerTime = new Date(item.registerTime).toLocaleString();
      });
      return this.waiters;
    },
  },
  methods: {
    // 全局封装分页查询
    findquery() {
      var pageobj = { page: this.currentPage - 1, pageSize: this.pageSize };
      pageobj = qs.stringify(pageobj);
      // console.log(pageobj);
      this.$axios.post("/waiter/query", pageobj).then((res) => {
        // console.log(res);
        this.waiters = res.data.data.list;
        this.total = res.data.data.total;
      });
    },
    //分页功能
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.findquery();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.findquery();
    },
    //审核按钮功能
    udt(row) {
      this.realname = row.realname;
      this.idCard = row.idCard;
      // console.log(row);
      this.form = {
        id: row.id,
        img1: row.idcardPhotoPositive,
        img2: row.idcardPhotoNegative,
      };
    },
    auditing() {
      this.$axios
        .get("/waiter/auditing", qs.stringify(this.form))
        .then((res) => {
          if (res.data.status == 200) {
            //保存成功
            //1.关闭模态框

            //2.刷新页面
            self.findquery();
            //3.提示用户保存成功-弹框
            this.$message({
              message: "审核成功",
              type: "success",
            });
          } else {
            //保存失败
            this.$message.error("审核失败", res.data.message);
          }
        });
    },
    reauditing() {
      var id = this.form.id;
      this.$axios
        .post("/waiter/refusauditing", { params: { id } })
        .then((res) => {
          if (res.data.status == 200) {
            //保存成功
            //1.关闭模态框

            //2.刷新页面
            self.findquery();
            //3.提示用户保存成功-弹框
            this.$message({
              message: "审核成功",
              type: "success",
            });
          } else {
            //保存失败
            this.$message.error("审核失败", res.data.message);
          }
        });
    },
  },
  created() {
    this.findquery();
  },
};
</script>
<style lang="scss" scoped>
#waiter {
  margin: 18px;
}
.el-input {
  width: 200px;
  margin-left: 20px;
}
.block {
  width: 150px;
  height: 100px;
  background-color: aquamarine;
}
</style>